const validator = {
    validatePhone: (rule, value, callback) => {
        if (!/^1[3|4|5|7|8][0-9]\d{8}$/.test(value)) {
            callback(new Error('请输入11位手机号码'))
        } else {
            callback()
        }
    },
    validateBank: (rule, value, callback) => {
        if (!/^([1-9]{1})(\d{14}|\d{18})$/.test(value)) {
            callback(new Error('请输入正确的银行卡号'))
        } else {
            callback()
        }
    },
    validateIdCard: (rule, value, callback) => {
        if (!/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(value)) {
            callback(new Error('请输入正确的身份证'))
        } else {
            callback()
        }
    }
    , noValidate: (rule, value, callback) => {
        callback()
    }
}

//  对Validator的实例重新封装成一个plugin ,方便 Vue.use(xxxx)
export default {
    install: function (Vue, Option) {
        Object.defineProperty(Vue.prototype, 'validator', {value: validator})
    }
}
